package com.wing.cms.dao;

import java.util.List;

import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
import org.springframework.stereotype.Repository;

import com.wing.common.CommonSpringJDBC;
import com.wing.common.util.PageBean;
import com.wing.cms.domain.Portlet;
import com.wing.cms.domain.Portlet1;

@Repository
public class Portlet1Dao extends CommonSpringJDBC<Portlet1, String> {

	public PageBean findPageList(int currentPage, int pageSize, Object... args) {
		String where= " 1=1 ";
		String sql1=" SELECT * FROM cms_portletinstance1 where "+where+" ORDER BY id ASC " +
			" LIMIT "+(currentPage-1) * pageSize+","+pageSize;
		String sql2 = "select count(id) from  cms_portletinstance1  where"+where;
		String[] sqlArray = {sql1,sql2 };
		return super.findPageList(sqlArray, currentPage, pageSize);
	}
	
	
	public Portlet1 findById(String id){
		String sql ="select a.*,b.channel_name as showChannelTitle from cms_portletinstance1 a ,cms_channel b where a.menuchannelId = b.id and a.Id = ? ";
		List list = super.getSimpleJdbcTemplate().queryForList(sql,id);
		if(list.size()==0){
			return null;
		}
		return super.getSimpleJdbcTemplate().queryForObject(sql, ParameterizedBeanPropertyRowMapper
						.newInstance(Portlet1.class), id);
	}
}
